package com.example.demo.excel.controller;

import com.example.demo.excel.db.entity.BaseTeacherInfo;
import com.example.demo.excel.service.BaseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author zjq
 * @version 创建时间：2021-12-16 16:40:55
 */

@RestController
@RequestMapping("/api/teacher")
@Api(value = "教师管理controller", tags = {"教师管理接口"})
public class BaseTeacherInfoController {

    @Autowired
    private BaseTeacherService baseTeacherService;

    @ApiOperation(value = "导出教师模板")
    @GetMapping(value = "/exportTeacherInfoTemplate")
    @ResponseBody
    public void exportTeacherInfoTemplate(HttpServletRequest req, HttpServletResponse resp) {
        baseTeacherService.exportTemplate(req, resp);
    }

    @ApiOperation(value = "教师批量导入")
    @PostMapping(value = "/importTeacherinfo")
    public void importTeacherinfo(@RequestBody MultipartFile file, HttpServletResponse resp) {
        Map<String, List<BaseTeacherInfo>> map = baseTeacherService.importExcelTeacherinfo(file);
        List<BaseTeacherInfo> liste = null;
        liste = map.get("liste");

        if (liste != null && liste.size() > 0) {
            baseTeacherService.exportTeacherinfo("teacherinfo" + System.currentTimeMillis(), liste, resp);
        }
    }
}
